package com.qf.request;

import java.util.List;

import ViewPagerLoadData.ParserViewPagerData;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.qf.bean.NewHomeAll;
import com.qf.config.AppConfig;

public class DownLoadNetHomeData
{
	static HttpUtils httpUtils;

	static String url = AppConfig.FENG_LEI;

	public static String loadDataFromServer(final Handler handler)
	{
		Log.i("info", "进入到下载函数中");
		if (httpUtils == null)
		{
			httpUtils = new HttpUtils();
		}
		httpUtils.send(HttpRequest.HttpMethod.GET, url,
				new RequestCallBack<String>()
				{

					@Override
					public void onFailure(HttpException arg0, String arg1)
					{
						Log.i("info", "网络状况不佳,请重新再试");
					}

					@Override
					public void onSuccess(ResponseInfo<String> arg0)
					{
						List<NewHomeAll> dataAlls = ParserViewPagerData
								.parseHomeData(arg0.result);

						Log.i("info", "解析fddf完成的数据为:" + dataAlls);
						Message msg = Message.obtain();
						msg.obj = dataAlls;
						msg.what = 0;
						handler.sendMessage(msg);
					}
				});
		return null;
	}
}
